﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sami_SMS_CRM_Business
{
    public class MtServiceLogRepository : Repository
    {
        public IList<mt_service_log> GetAll(string subscriber, int? advertisment_id, int? collection_id, string status, DateTime? timeFrom, DateTime? timeTo,
                                        int currentPage, int pageSize, ref int totalRecord)
        {
            var retValue = DB.mt_service_logs.Where(p =>
                                        (string.IsNullOrEmpty(subscriber) ? true : (p.subs.Contains(subscriber))) &&
                                        (advertisment_id == null ? true : (p.advertisment_id == advertisment_id)) &&
                                        (collection_id == null ? true : (p.collection_id == collection_id)) &&
                                        (string.IsNullOrEmpty(status) ? true : (p.status.Contains(status))) &&
                                        (timeFrom == null ? true : (p.date_time >= timeFrom)) &&
                                        (timeTo == null ? true : (p.date_time <= timeTo))
                                     )
                                    .OrderByDescending(p => p.date_time);
            totalRecord = retValue.Count();
            return retValue.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList();
        }
    }
}
